import threading
import time

"""
模拟一个假的异步操作
"""

def producer():
    print('厨师：等人买包子')
    event.wait() # block uttil the internal flag is true
    event.clear() # reset internal flag to false
    print('厨师：有人来买包子了，开始做包子')
    time.sleep(3)
    print('厨师：你的包子做好了')
    event.set() # set the internal flag to true

def consumer():
    print('客户：老板，买包子')
    event.set()
    time.sleep(1)
    print('客户：老板，快点')
    event.wait()
    print('客户：谢谢老板，真好吃')

event = threading.Event()
p = threading.Thread(target=producer)
c = threading.Thread(target=consumer)
p.start()
c.start()